package top.weiliang.springboot3.aop;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import top.weiliang.springboot3.exception.AppException;
import top.weiliang.springboot3.service.auth.AuthService;

@Aspect
@Slf4j
@Component
@RequiredArgsConstructor
@Order(100)
public class ControllerAuth implements ControllerPointCut {
    private final AuthService authService;

    @Before("pointcut()")
    public void before(JoinPoint jp) {
        if (!authService.checkAuth()) {
            throw AppException.create("需要相关角色的用户登录才能访问！", 1000);
        }
    }


}